package com.prs.crm.dao.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.DistrictDao;
import com.prs.crm.domain.District;

public class DistrictDaoImpl extends BaseDaoImpl<District> implements DistrictDao{
	
	@SuppressWarnings("unchecked")
	public Collection<District> getRootDistricts()
	{
		return (Collection<District>)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(District.class);
				        	criteria.add(Restrictions.isNull("parent"));
				         	criteria.addOrder(Order.asc("id"));
				        	return criteria.list();
				        }   
				 } );
	}

}
